<?php


abstract class Controller_Site extends Controller_Template {
    
    /**
     * 
     * Az oldal tartalma
     * @var View
     */
    var $content = "";
    
    /**
    * Loads the content [View] object.
    */
    public function before()
    {
        parent::before();
        $this->content = View::factory($this->request->controller() . '/' . $this->request->action());
    }
    
    /**
    * Assigns the content [View] as the request response.
    */
    public function after()
    {
        $this->template->set('content', $this->content);
        
        if($this->hasFlash('notice'))
            $this->template->set('notice', $this->getFlash('notice'));
        
        if($this->hasFlash('error'))
            $this->template->set('error', $this->getFlash('error'));
        
        parent::after();
    }
    
    protected function setVar($key, $value) {
        $this->content->set($key, $value);
    }
    
    public function setFlash($key, $value) {
        Session::instance()->set($key, $value);
    }
    
    public function hasFlash($key) {
        $value = Session::instance()->get($key, null);
        return $value != null;
    }
    
    public function getFlash($key) {
        return Session::instance()->get_once($key);
    }
}